<?php
/**
 * @author: <136327134@qq.com>
 * @day: 2021/6/11
 */

namespace App\Services\system;

use App\Services\BaseServices;
use App\Dao\system\SystemLogDao;
use Hlcreation\Services\CloudLogServices;
use App\Dao\store\StoreDao;




/**
 * service
 */
class SystemLogServices extends BaseServices
{


    /**
     * SystemDaoServices constructor.
     * @param SystemLogDao $dao
     */
    public function __construct(SystemLogDao $dao)
    {

        $this->dao = $dao;

    }

    /**
     *插入操作日志
     */
    public  function  SaveLog($admin_id,$title,$content){

        $arr['ip']=app('request')->ip();
        $arr['type']=1;
        $arr['created_at']=date('Y-m-d H:i:s');
        $arr['admin_id']=$admin_id;
        $arr['title']=$title;
        $arr['content']=$content;
        return $this->dao->create($arr);
    }


    /**
     * 查询操作日志
     */
    public  function  LogList($where){

        $nowdate = date("Y-m-d");
        $sevendate = date("Y-m-d", strtotime(" -7 day"));
        $between =  !empty($where['create_time']) ? [$where['create_time']." 00:00:00", $where['create_time']." 23:59:59"] : [$sevendate." 00:00:00", $nowdate." 23:59:59"];
        $where['nowdate']=$nowdate;
        $where['sevendate']=$sevendate;
        $where['between']=$between;

        if($where['type']==1){
        return   $this->dao->LogList($where);
        }else {
            $StoreServices = app()->make(StoreDao::class);
            if($where['user_id']==1)
                $store_data=  $StoreServices->getList([],['id']);
            else
               $store_data=  $StoreServices->getList(['creator_uid'=>$where['user_id']],['id']);
            $arr_store = array_column($store_data, 'id');

            $where['uniacid_id']= $arr_store;
            return   CloudLogServices::logList($where);
        }
    }



}
